<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../lib/vue.js"></script>
</head>

<body>
    <div id="root">
        <h2>当前的n值是：{{n}}</h2>
        <button @click="add">点我n+1</button>
        <button @click="bye">销毁 </button>
    </div>
</body>
<script>
    Vue.config.productionTip = false;

    new Vue({
        el: "#root",
        data: {
            n: 1
        },
        methods: {
            add() {
                this.n++;
            },
            bye() {
                console.log("bye");
                this.$destroy();
            }
        },

        //此时this没有_data
        beforeCreate() {
            console.log("beforeCreate");
        },

        created() {
            console.log("created");
        },

        //页面呈现的是未经编译的DOM，所有对DOM的操作，最终是不奏效的
        beforeMount() {
            console.log("beforeMount");
        },

        //页面中呈现的是经过编译的DOM，此时对DOM的操作均有效
        mounted() {
            console.log("mounted");
        },

        //数据是新的，但是页面时旧的
        beforeUpdate() {
            console.log("beforeUpdate");
        },

        updated() {
            console.log("updated");
        },

        //vm中所有data methods 指令等，都处于可用状态，马上销毁，一般在此关闭定时器，取消订阅，解绑自定义事件
        beforeDestroy() {
            console.log("beforeDestroy");
        },

        destroyed() {
            console.log("destroyed");
        },
    })
</script>

</html>